package com.fjnu.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Slf4j
@Component
public class LogsAspect {
    @Pointcut("execution(* com.fjnu.dao..select*(..))")
    public void selectPointCut() {
    }
    @Pointcut("execution(* com.fjnu.dao..update*(..))")
    public void updatePointCut() {}

    @Around("selectPointCut()||updatePointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long end = System.currentTimeMillis();
        if (end-start > 3000){
            log.info("[ERROR]" + joinPoint.getSignature().getName() + "'s running time is too long ", end - start);
        }
        return proceed;
    }
}
